package com.xhh.nphm.web.controller.system;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.xhh.nphm.common.annotation.RepeatSubmit;
import com.xhh.nphm.common.core.controller.BaseController;
import com.xhh.nphm.common.core.domain.AjaxResult;
import com.xhh.nphm.common.core.domain.entity.SysUser;
import com.xhh.nphm.common.utils.DateUtils;
import com.xhh.nphm.common.utils.ShiroUtils;
import com.xhh.nphm.common.utils.StringUtils;
import com.xhh.nphm.common.utils.bean.BeanUtils;
import com.xhh.nphm.common.utils.sms.SmsUtils;
import com.xhh.nphm.system.domain.SmsNote;
import com.xhh.nphm.system.domain.TwfSendBackEty;
import com.xhh.nphm.system.domain.TworkFormBaseEty;
import com.xhh.nphm.system.domain.TworkFormLogEty;
import com.xhh.nphm.system.mapper.CommonDao;
import com.xhh.nphm.system.service.*;
import io.swagger.models.auth.In;
import org.aspectj.weaver.ast.Var;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView;

import java.util.*;

@RestController
public class SendSonCtrl extends BaseController {
    private String prefix = "system/mTelWF";
    @Autowired
    private CommonDao commonDao;
    @Autowired
    private WfSendBackController wfSendBackController;
    @Autowired
    private MTelWFcmnFileController mTelWFcmnFileController;
    @Autowired
    private IWorkFormBaseService workFormBaseService;
    @Autowired
    private IWfSendBackService wfSendBackService;
    @Autowired
    private ITelWFLogService telWFLogService;

    @Autowired
    private ISmsNoteService smsNoteService;

    @Autowired
    private ITagService tagService;

    /**
     * 拟派下级派单页面
     *
     * @return
     */
    @GetMapping("/system/mTelWF/cmnFile/telresendto/{wfId}")
    public ModelAndView telresendto(@PathVariable Integer wfId, Integer sbId, ModelMap map) {
        SysUser user = ShiroUtils.getSysUser();
        Long deptId = user.getDeptId();
        TworkFormBaseEty tworkFormBaseEty = workFormBaseService.getById(wfId);
        TwfSendBackEty sendBackEty = tworkFormBaseEty.getTwfSendBackEty();
        sendBackEty.setSdeptId(deptId.toString());
        sendBackEty.setSdeptName(user.getDeptName());
        sendBackEty.setSuserNo(user.getUserNo());
        sendBackEty.setSuserName(user.getUserName());
        map.put("workFormBase", tworkFormBaseEty);
        map.put("sbId", sbId);
        map.put("wfId", tworkFormBaseEty.getPkId());
        map.put("telId", tworkFormBaseEty.getGetDealPk());
        map.put("sdeptName", user.getDept().getDeptShort());
        map.put("sdeptId", sendBackEty.getSdeptId());
        map.put("suserName", sendBackEty.getSuserName());
        map.put("suserNo", sendBackEty.getSuserNo());
        map.put("deptId", user.getDeptId());
        map.put("sendTime", DateUtils.getTime());
        return new ModelAndView(prefix + "/cmnFile/telresendto");
    }

    /**
     * 下派操作
     * @param twfSendBackEty
     * @return
     */
    @RepeatSubmit
    @PostMapping("/system/mTelWF/cmnFile/dlSendToSon")
    public AjaxResult sendToSon(TwfSendBackEty twfSendBackEty,Integer smsInform, String workFormNo,  String zpFlag) {
        boolean opResult = false;
        TworkFormBaseEty tworkFormBaseEty = new TworkFormBaseEty();
        if (IS_GAOXIN()){
            //高新区
            opResult = doAction_gxq(twfSendBackEty, tworkFormBaseEty, zpFlag);
        }else{
            opResult = doAction(twfSendBackEty, tworkFormBaseEty);
        }
        if (opResult) {
            doOtherLogic(twfSendBackEty, tworkFormBaseEty);
        }
        //判断是否发送短信
        if(StringUtils.isNotNull(smsInform) && smsInform == 1){
            smsNoteService.sendSmsNote(twfSendBackEty.getSbdeptId(),workFormNo,"派单");
        }
        // wfSendBackController.sendSon(twfSendBackEty);
        return toAjax(opResult);
    }

    /**
     * 签收列表的拟派下级派单页面
     *
     * @return
     */
    @GetMapping("/system/mTelWF/cmnFile/transferSendToSon/{wfId}")
    public ModelAndView transferSendToSon(@PathVariable Integer wfId,Integer sbId, ModelMap map) {
        SysUser user = ShiroUtils.getSysUser();
        Long deptId = user.getDeptId();
        TworkFormBaseEty tworkFormBaseEty = workFormBaseService.getById(wfId);
        TwfSendBackEty sendBackEty = tworkFormBaseEty.getTwfSendBackEty();
        // 查询工单已有标签
        List<Map<String, Object>> telExistTags = tagService.selectTelExistTag(String.valueOf(tworkFormBaseEty.getGetDealPk()),user.getDeptId().toString(),user.getUserId().toString());
        if(telExistTags != null && telExistTags.size() > 0){
            map.put("wfTag",telExistTags);
        }
        sendBackEty.setSdeptId(deptId.toString());
        sendBackEty.setSdeptName(user.getDeptName());
        sendBackEty.setSuserNo(user.getUserNo());
        sendBackEty.setSuserName(user.getUserName());
        //TODO 设置办理期限 不是二级部门（锦江区），把派单的办理期限设置为父级派单办理期限
        if(sbId != null) {
            TwfSendBackEty psendBack = wfSendBackService.selectByPkId(sbId);
            map.put("pbackLimit", psendBack.getBackLimit());
            map.put("sendBack",psendBack);
        }
        else {
            QueryWrapper<TwfSendBackEty> queryWrapper = new QueryWrapper<TwfSendBackEty>();
            queryWrapper.eq("wfId", wfId);
            queryWrapper.eq("sbdeptId", deptId.toString());
            queryWrapper.eq("isDel", 0);
            List<TwfSendBackEty> list = wfSendBackService.list(queryWrapper);
            if(list != null && list.size() > 0) {
                map.put("pbackLimit", list.get(0).getBackLimit());
            }
        }

        map.put("workFormBase", tworkFormBaseEty);
        map.put("sbId", sbId);
        map.put("wfId", tworkFormBaseEty.getPkId());
        map.put("telId", tworkFormBaseEty.getGetDealPk());
        map.put("sdeptName", user.getDept().getDeptShort());
        map.put("sdeptId", sendBackEty.getSdeptId());
        map.put("suserName", sendBackEty.getSuserName());
        map.put("suserNo", sendBackEty.getSuserNo());
        map.put("deptId", user.getDeptId());
        map.put("sendTime", DateUtils.getTime());
        return new ModelAndView(prefix + "/cmnFile/transferSendToSon");
    }

    /**
     * 提交转派：签收列表点击转派后，再点提交
     * 回复页面的增派
     * 待分发到下级的派单
     * @param twfSendBackEty
     * @return
     */
    @PostMapping("/system/mTelWF/cmnFile/transferSendToSon")
    public AjaxResult transferSendToSon(TwfSendBackEty twfSendBackEty) {
        TwfSendBackEty preTwfSendBack = new TwfSendBackEty();
        preTwfSendBack.setPkId(twfSendBackEty.getPkId());
        preTwfSendBack.setSendState(22);
        TworkFormBaseEty preWorkFormBase = new TworkFormBaseEty();
        preWorkFormBase.setPkId(twfSendBackEty.getWfId());
        preWorkFormBase.setCrtStepId(400);
        preWorkFormBase.setCrtStepName("市级主办处理中");
//        mTelWFcmnFileController.showWorkFormJson(preTwfSendBack,preWorkFormBase);
        boolean opResult = true;
//        TworkFormBaseEty tworkFormBaseEty = new TworkFormBaseEty();
//        opResult = doAction(twfSendBackEty, tworkFormBaseEty);
//        if (opResult) {
//            doOtherLogic(twfSendBackEty, tworkFormBaseEty);
//        }
        return toAjax(opResult);
    }

    private boolean doAction(TwfSendBackEty twfSendBack, TworkFormBaseEty tworkFormBaseEty) {
        String deptId = getSysUser().getDeptId().toString();
        TwfSendBackEty etyMain = new TwfSendBackEty();
        BeanUtils.copyBeanProp(etyMain, twfSendBack);
        tworkFormBaseEty = workFormBaseService.getById(twfSendBack.getWfId());
        if (tworkFormBaseEty != null && tworkFormBaseEty.getPkId() > 0) {
            // TODO: 未完善
            // 拟派给主办单位  统一为主办单位     协办单位不需要了
            etyMain.setGetDealPk(tworkFormBaseEty.getGetDealPk());
            etyMain.setCallId(tworkFormBaseEty.getCallId());
            etyMain.setTapeId(tworkFormBaseEty.getTapeId());
            etyMain.setWfId(tworkFormBaseEty.getPkId());
        }
        int oriLevel = 1;
        if (!"304".equals(deptId) && deptId.length() == 3)
            oriLevel = 2;
        else
            oriLevel = deptId.length() / 3;
        etyMain.setOriLevel(oriLevel);
        etyMain.setSendState(10);
        etyMain.setSendTime(new Date());
        etyMain.setBackState(0);
        etyMain.setSortCode("11");
        etyMain.setSortName("主办");
        etyMain.setDealCode("11");
        //设置派单的父id
        Integer pid = twfSendBack.getPid();
        if(pid == null || pid <= 0) {
            //不用每个地方都从页面把pid传够了，容易绕晕，但父id不是百分百准确
            QueryWrapper<TwfSendBackEty> queryWrapper = new QueryWrapper<>();
            queryWrapper.select("top 1 pkId");
            queryWrapper.eq("wfId", twfSendBack.getWfId());
            queryWrapper.eq("SBDeptId",getSysUser().getDeptId());
            queryWrapper.orderByDesc("pkId");
            List<TwfSendBackEty> list = wfSendBackService.list(queryWrapper);
            if(list != null && list.size() > 0) {
                pid = list.get(0).getPkId();
            }
        }
        etyMain.setPid(pid);

        //拟派多个部门
        if(StringUtils.isNotEmpty(twfSendBack.getSbdeptId())) {
            String[] arrDetpIdX = twfSendBack.getSbdeptId().split(",");
            String[] arrDetpNameX = twfSendBack.getSbdeptName().split(",");
            for (int i = 0; i < arrDetpIdX.length; i++) {
                etyMain.setSbdeptId(arrDetpIdX[i]);
                etyMain.setSbdeptName(arrDetpNameX[i]);
                try
                {
                    wfSendBackService.save(etyMain);
                }
                catch (Exception e) {
                    this.logger.debug("add main [tWfSendBack] fail: " + e.getMessage());
                    return false;
                }
            }
        }
        //更新父级派单状态
        //注意twfSendBack.getPkId是页面传过来的父派单id etyMain.getPkId是当前派单id
        //commonDao.proTsubBackState(twfSendBack.getWfId(), etyMain.getPkId());
        UpdateWrapper<TwfSendBackEty> updateWrapper = new UpdateWrapper<>();
        updateWrapper.set("subBackState", "未回复");
        updateWrapper.eq("pkId", twfSendBack.getPkId());
        wfSendBackService.update(updateWrapper);
        return true;
    }

    private boolean doAction_gxq(TwfSendBackEty twfSendBack, TworkFormBaseEty tworkFormBaseEty, String zpFlag) {
        SysUser user = getSysUser();
        TwfSendBackEty etyMain = new TwfSendBackEty();
        BeanUtils.copyBeanProp(etyMain, twfSendBack);
        tworkFormBaseEty = workFormBaseService.getById(twfSendBack.getWfId());
        if (tworkFormBaseEty != null && tworkFormBaseEty.getPkId() > 0) {
            // TODO: 未完善
            // 拟派给主办单位  统一为主办单位     协办单位不需要了
            etyMain.setGetDealPk(tworkFormBaseEty.getGetDealPk());
            etyMain.setCallId(tworkFormBaseEty.getCallId());
            etyMain.setTapeId(tworkFormBaseEty.getTapeId());
            etyMain.setWfId(tworkFormBaseEty.getPkId());
        }
        int oriLevel = 1;
        if (!"304".equals(user.getDeptId().toString()) && user.getDeptId().toString().length() == 3)
            oriLevel = 2;
        else
            oriLevel = user.getDeptId().toString().length() / 3;
        etyMain.setOriLevel(oriLevel);
        etyMain.setSendState(10);
        etyMain.setSendTime(new Date());
        etyMain.setBackState(0);
        etyMain.setSortCode("11");
        etyMain.setSortName("主办");
        etyMain.setDealCode("11");
        //设置派单的父id
        Integer pid = twfSendBack.getPid();
        if(pid == null || pid <= 0) {
            //不用每个地方都从页面把pid传够了，容易绕晕，但父id不是百分百准确
            QueryWrapper<TwfSendBackEty> queryWrapper = new QueryWrapper<>();
            queryWrapper.select("top 1 pkId");
            queryWrapper.eq("wfId", twfSendBack.getWfId());
            queryWrapper.eq("SBDeptId",getSysUser().getDeptId());
            queryWrapper.orderByDesc("pkId");
            List<TwfSendBackEty> list = wfSendBackService.list(queryWrapper);
            if(list != null && list.size() > 0) {
                pid = list.get(0).getPkId();
            }
        }
        etyMain.setPid(pid);
        //拟派多个部门
        if(StringUtils.isNotEmpty(twfSendBack.getSbdeptId())) {
            String[] arrDetpIdX = twfSendBack.getSbdeptId().split(",");
            String[] arrDetpNameX = twfSendBack.getSbdeptName().split(",");
            String[] zpFlagS = zpFlag.split(",");
            for (int i = 0; i < arrDetpIdX.length; i++) {
                etyMain.setSbdeptId(arrDetpIdX[i]);
                etyMain.setSbdeptName(arrDetpNameX[i]);
                etyMain.setSdeptId(twfSendBack.getSdeptId());
                etyMain.setSdeptName(twfSendBack.getSdeptName());
                etyMain.setPid(pid);
                etyMain.setSendDesc("请 "+arrDetpNameX[i]+" 调查处理后直接与来话人联系，并将处理结果抄复我办。请注意来话人个人信息保密。");
                if(zpFlagS[i].equals("10")){ //直派单
                    etyMain.setSendSpare("1"); //直派
                    directWF(etyMain,user);
                }else{
                    try {
                        wfSendBackService.save(etyMain);
                    } catch (Exception e) {
                        this.logger.debug("add main [tWfSendBack] fail: " + e.getMessage());
                        return false;
                    }
                }
                //更新父级派单状态
                //注意twfSendBack.getPkId是页面传过来的父派单id etyMain.getPkId是当前派单id
                commonDao.proTsubBackState(twfSendBack.getWfId(), etyMain.getPkId());
                // UpdateWrapper<TwfSendBackEty> updateWrapper = new UpdateWrapper<>();
                // updateWrapper.set("subBackState", "未回复");
                // updateWrapper.eq("pkId", twfSendBack.getPkId());
                // wfSendBackService.update(updateWrapper);
            }
        }
        return true;
    }

    //直派
    public boolean directWF(TwfSendBackEty sendBackEty,SysUser user){
        String deptNo ="",deptName="";
        //查询直派部门的上级部门
        Map<String, Object> handleDept = commonDao.queryDirectParentDept(sendBackEty.getSbdeptId());
        if (!handleDept.isEmpty()) {
            deptNo = (String)handleDept.get("noUnit");
            deptName = (String)handleDept.get("deptShort");
        }
        TwfSendBackEty newSendBackEty = new TwfSendBackEty();
        BeanUtils.copyBeanProp(newSendBackEty, sendBackEty);
        //市--中--直派部门
        newSendBackEty.setSendState(23);//已派下级
        newSendBackEty.setSbdeptId(deptNo);
        newSendBackEty.setSbdeptName(deptName);
        newSendBackEty.setSendDesc("请 "+deptName+" 调查处理后直接与来话人联系，并将处理结果抄复我办。请注意来话人个人信息保密。");
        wfSendBackService.save(newSendBackEty);//fu -- 上级部门
        sendBackEty.setSdeptId(deptNo);
        sendBackEty.setSdeptName(deptName);
        //zi -- 更新pid
        sendBackEty.setPid(newSendBackEty.getPkId());
        wfSendBackService.save(sendBackEty);
        //记录直派操作日志
        TworkFormLogEty etyLog = new TworkFormLogEty();
        etyLog.setWfId(sendBackEty.getWfId());
        etyLog.setOpDeptNo(String.valueOf(user.getDeptId()));
        etyLog.setOpDeptName(user.getDeptName());
        etyLog.setOpUserNo(user.getUserNo());
        etyLog.setOpUserName(user.getUserName());
        etyLog.setOpAction("直派");
        etyLog.setOpBtnId(-1);
        String desc = "增派办理部门（" + sendBackEty.getSbdeptName() + "）";
        etyLog.setWsDesc(desc);
        etyLog.setWsOpen(1);
        etyLog.setOpDesc("直派下级部门（主办："+ sendBackEty.getSbdeptName() +"）");
        etyLog.setEffectFlag(1);
        return telWFLogService.save(etyLog);
    }

    private boolean doOtherLogic(TwfSendBackEty twfSendBack, TworkFormBaseEty tworkFormBase)
    {
        boolean rtnFlag = false;
        SysUser ssnUser = getSysUser();

        // 把派单状态更新为下派 新增签收日期
        UpdateWrapper<TwfSendBackEty> updateWrapper = new UpdateWrapper<>();
        TwfSendBackEty oldSendBack = wfSendBackService.selectByPkId(twfSendBack.getPkId());
        if(oldSendBack != null && oldSendBack.getGetTime() == null) {
            updateWrapper.set("getTime", new Date());
            updateWrapper.set("getPerson", ssnUser.getUserNo());
            updateWrapper.set("getPerTel", ssnUser.getNoTel());
        }
        updateWrapper
                .set("sendState", 23)
                .eq("PkId", twfSendBack.getPkId());
        rtnFlag = wfSendBackService.update(updateWrapper);

        // 更新工单流程步骤
        UpdateWrapper<TworkFormBaseEty> updateWrapper2 = new UpdateWrapper<>();
        tworkFormBase.setCrtStepId(400);
        tworkFormBase.setCrtStepName("市级部门处理中");
        updateWrapper2.set("crtStepId", tworkFormBase.getCrtStepId())
                .set("crtStepName", tworkFormBase.getCrtStepName())
                .set("crtStepTime", new Date())
                .set("WsUFlag", 1)
                .eq("PkId", tworkFormBase.getPkId());
        rtnFlag = workFormBaseService.update(updateWrapper2);

        // 记录操作日志
        TworkFormLogEty etyLog = new TworkFormLogEty();
        etyLog.setWfId(twfSendBack.getWfId());
        etyLog.setOpDeptNo(String.valueOf(ssnUser.getDeptId()));
        etyLog.setOpDeptName(ssnUser.getDeptName());
        etyLog.setOpUserNo(ssnUser.getUserNo());
        etyLog.setOpUserName(ssnUser.getUserName());
        etyLog.setOpAction("派单到下级部门");
        etyLog.setOpBtnId(-1);
//        String temp = request.getParameter("tbDeptNameX");
        String temp = twfSendBack.getSbdeptName();
        if (temp.lastIndexOf(",") > 0)
            temp = temp.substring(0, temp.length() - 1);
        String desc = "主办：";
        desc = desc + temp;
//        temp = request.getParameter("tbDeptNameY");
//        if (temp.lastIndexOf(",") > 0)
//            temp = temp.substring(0, temp.length() - 1);
//        if (temp.length() > 0) {
//            desc = desc + "；协办：" + temp;
//        }
        etyLog.setWsDesc("转办工单（" + desc + "）");
        etyLog.setWsOpen(1);
        etyLog.setOpDesc("提交到下级部门（" + desc + "）");
        etyLog.setEffectFlag(1);
        telWFLogService.save(etyLog);
        return rtnFlag;
    }

    /**
     * 拟派下级派单页面
     *
     * @return
     */
    @GetMapping("/system/mTelWF/cmnFile/tabSendToSon/{wfId}")
    public ModelAndView dlSendToSon(@PathVariable Integer wfId,Integer sbId, ModelMap map) {
        SysUser user = ShiroUtils.getSysUser();
        Long deptId = user.getDeptId();
        TworkFormBaseEty tworkFormBaseEty = workFormBaseService.getById(wfId);
        TwfSendBackEty sendBackEty = tworkFormBaseEty.getTwfSendBackEty();
        sendBackEty.setSdeptId(deptId.toString());
        sendBackEty.setSdeptName(user.getDeptName());
        sendBackEty.setSuserNo(user.getUserNo());
        sendBackEty.setSuserName(user.getUserName());
        map.put("workFormBase", tworkFormBaseEty);
        map.put("sbId", sbId);
        map.put("wfId", tworkFormBaseEty.getPkId());
        map.put("telId", tworkFormBaseEty.getGetDealPk());
        map.put("sdeptName", user.getDept().getDeptShort());
        map.put("sdeptId", sendBackEty.getSdeptId());
        map.put("suserName", sendBackEty.getSuserName());
        map.put("suserNo", sendBackEty.getSuserNo());
        map.put("deptId", user.getDeptId());
        map.put("sendTime", DateUtils.getTime());
        return new ModelAndView(prefix + "/cmnFile/tabSendToSon");
    }

    /**
     * 承办部门选择
     *
     * @return
     */
    @GetMapping("/system/mTelWF/cmnFile/deptAllM2")
    public ModelAndView deptAllM(ModelMap map) {
        map.put("areaNo", getSysUser().getAreaNo());
        map.put("deptId", getSysUser().getDeptId());
        return new ModelAndView(prefix + "/cmnFile/deptAllM2");
    }

    /**
     * 批量派单
     * @return
     */
    @PostMapping("/system/mTelWF/cmnFile/batchSendToSon")
    public AjaxResult batchSendToSon(TwfSendBackEty twfSendBackEty,String pkIds, String wfIds, String zpFlag) {
        if (IS_GAOXIN()){
            return batchSendToSon_gxq(twfSendBackEty,pkIds,wfIds,zpFlag);
        }else{
            return batchSendToSon_general(twfSendBackEty,pkIds,wfIds);
        }
    }

    public AjaxResult batchSendToSon_general(TwfSendBackEty twfSendBackEty,String pkIds, String wfIds) {
        boolean opResult = false;
        if(StringUtils.isNotNull(pkIds)&&StringUtils.isNotNull(wfIds)){
            if(pkIds.contains(",") && wfIds.contains(",")){
                String[] pkId = pkIds.split(",");
                String[] wfId = wfIds.split(",");
                for (int i = 0; i < pkId.length; i++) {
                    twfSendBackEty.setPkId(Integer.parseInt(pkId[i]));
                    twfSendBackEty.setWfId(Integer.parseInt(wfId[i]));
                    TworkFormBaseEty tworkFormBaseEty = new TworkFormBaseEty();
                    opResult = doAction(twfSendBackEty, tworkFormBaseEty);
                    if (opResult) {
                        doOtherLogic(twfSendBackEty, tworkFormBaseEty);
                    }
                }
            }else{
                twfSendBackEty.setPkId(Integer.parseInt(pkIds));
                twfSendBackEty.setWfId(Integer.parseInt(wfIds));
                TworkFormBaseEty tworkFormBaseEty = new TworkFormBaseEty();
                opResult = doAction(twfSendBackEty, tworkFormBaseEty);
                if (opResult) {
                    doOtherLogic(twfSendBackEty, tworkFormBaseEty);
                }
            }
        }else{
            return error();
        }
        return toAjax(opResult);
    }

    public AjaxResult batchSendToSon_gxq(TwfSendBackEty twfSendBackEty,String pkIds, String wfIds, String zpFlag) {
        boolean opResult = false;
        if(StringUtils.isNotNull(pkIds)&&StringUtils.isNotNull(wfIds)){
            if(pkIds.contains(",") && wfIds.contains(",")){
                String[] pkId = pkIds.split(",");
                String[] wfId = wfIds.split(",");
                String[] zpFlagS = zpFlag.split(",");
                for (int i = 0; i < pkId.length; i++) {
                    twfSendBackEty.setPkId(Integer.parseInt(pkId[i]));
                    twfSendBackEty.setWfId(Integer.parseInt(wfId[i]));
                    TworkFormBaseEty tworkFormBaseEty = new TworkFormBaseEty();
                    opResult = doAction_gxq(twfSendBackEty, tworkFormBaseEty,zpFlagS[i]);
                    if (opResult) {
                        doOtherLogic(twfSendBackEty, tworkFormBaseEty);
                    }
                }
            }else{
                twfSendBackEty.setPkId(Integer.parseInt(pkIds));
                twfSendBackEty.setWfId(Integer.parseInt(wfIds));
                TworkFormBaseEty tworkFormBaseEty = new TworkFormBaseEty();
                opResult = doAction_gxq(twfSendBackEty, tworkFormBaseEty,zpFlag);
                if (opResult) {
                    doOtherLogic(twfSendBackEty, tworkFormBaseEty);
                }
            }
        }else{
            return error();
        }
        return toAjax(opResult);
    }
}
